﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using SMALLERP;
using SMALLERP.DataClass;

namespace XJLSC.QM
{
    public partial class OQCprint : Form
    {
        public delegate void Cdgzzx(object sender, EventArgs e);
        //定义委托对象
        public Cdgzzx cdgzzx;
        private readonly DataBase db = new DataBase();
        public OQCprint()
        {
            InitializeComponent();
        }

        private void OQCprint_Load(object sender, EventArgs e)
        {
            ///----指定报表外部数据源
            DataTable table1 = new DataTable();
            DataTable table2 = new DataTable();
            DataTable table3 = new DataTable();
            DataTable table4 = new DataTable();

            string strSql = null;
            if (QMFOQC.LX == "OQC")
            {
                strSql = "SELECT TO001,TO002,TO003,QMSTB.UDF01,TC005,ROUND(QMSTC.UDF51,2) AS UDF51 FROM COPTO LEFT JOIN QMSTB ON TO001=TB001 AND TO002=TB002 AND TO003=TB003 LEFT JOIN QMSTC ON TB001=TC001 AND TB002=TC002 AND TB003=TC003 AND TB004=TC004 AND TB014=TC008 AND TBC01=TCC01 WHERE TO001='" + QMFOQC.DB + "' AND TO002='" + QMFOQC.DH + "' AND TO003='" + QMFOQC.XH + "' AND ISNULL(TC005,'')<>'' AND QMSTB.UDF02='尺寸检查'";
            }

            if (QMFOQC.LX == "FQC")
            {
                strSql = "SELECT TA001,TA002,'0000',QMSTB.UDF01,TC005,ROUND(QMSTC.UDF51,2) AS UDF51 FROM MOCTA LEFT JOIN QMSTB ON TA001=TB001 AND TA002=TB002 LEFT JOIN QMSTC ON TB001=TC001 AND TB002=TC002 AND TB003=TC003 AND TB004=TC004 AND TB014=TC008 AND TBC01=TCC01 WHERE TA001='" + QMFOQC.DB + "' AND TA002='" + QMFOQC.DH + "' AND ISNULL(TC005,'')<>'' AND TB014='" + QMFOQC.CS + "' AND TBC01='" + QMFOQC.JYPC + "' AND QMSTB.UDF02='尺寸检查'";
            }

            try
            {
                table1 = db.GetDataSet1(strSql, "QMSMG").Tables["QMSMG"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                return;
            }
            if (QMFOQC.LX == "OQC")
            {
                strSql = "SELECT TO001,TO002,TO003,QMSTB.UDF01,TC005,ROUND(QMSTC.UDF51,2) AS UDF51 FROM COPTO LEFT JOIN QMSTB ON TO001=TB001 AND TO002=TB002 AND TO003=TB003 LEFT JOIN QMSTC ON TB001=TC001 AND TB002=TC002 AND TB003=TC003 AND TB004=TC004 AND TB014=TC008 AND TBC01=TCC01 WHERE TO001='" + QMFOQC.DB + "' AND TO002='" + QMFOQC.DH + "' AND TO003='" + QMFOQC.XH + "' AND ISNULL(TC005,'')<>'' AND QMSTB.UDF02='功能检查'";
            }
            if (QMFOQC.LX == "FQC")
            {
                strSql = "SELECT TA001,TA002,'0000',QMSTB.UDF01,TC005,ROUND(QMSTC.UDF51,2) AS UDF51 FROM MOCTA LEFT JOIN QMSTB ON TA001=TB001 AND TA002=TB002 LEFT JOIN QMSTC ON TB001=TC001 AND TB002=TC002 AND TB003=TC003 AND TB004=TC004 AND TB014=TC008 AND TBC01=TCC01 WHERE TA001='" + QMFOQC.DB + "' AND TA002='" + QMFOQC.DH + "' AND ISNULL(TC005,'')<>'' AND TB014='" + QMFOQC.CS + "' AND TBC01='" + QMFOQC.JYPC + "' AND QMSTB.UDF02='功能检查'";
            }
            try
            {
                table2 = db.GetDataSet1(strSql, "QMSMG").Tables["QMSMG"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                return;
            }
            strSql = "SELECT UDF01,UDF02,TB018,UDF51,UDF52,UDF53 FROM QMSTB WHERE TB001='" + QMFOQC.DB + "' AND TB002='" + QMFOQC.DH + "' AND TB003='" + QMFOQC.XH + "' AND TB016='4' AND TB014='" + QMFOQC.CS + "' AND TBC01='" + QMFOQC.JYPC + "' AND QMSTB.UDF02='功能检查'";
            try
            {
                table3 = db.GetDataSet1(strSql, "QMSMG").Tables["QMSMG"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                return;
            }

            strSql = "SELECT UDF01,UDF02,TB012,TB018,UDF51,UDF52,UDF53 FROM QMSTB WHERE TB001='" + QMFOQC.DB + "' AND TB002='" + QMFOQC.DH + "' AND TB003='" + QMFOQC.XH + "' AND TB016='4'  AND TB014='" + QMFOQC.CS + "' AND TBC01='" + QMFOQC.JYPC + "' AND QMSTB.UDF02='包装检查'";
            //MessageBox.Show(strSql.ToString(), "软件提示");
            try
            {
                table4 = db.GetDataSet1(strSql, "QMSMG").Tables["QMSMG"];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "软件提示");
                return;
            }


            ///---添加数据源
            ReportDataSource rds1 = new ReportDataSource();
            rds1.Name = "DataSet1";
            rds1.Value = table1;
            ///---向报表绑定数据源
            this.reportViewer1.LocalReport.DataSources.Add(rds1);

            ///---添加数据源
            ReportDataSource rds2 = new ReportDataSource();
            rds2.Name = "DataSet2";
            rds2.Value = table2;
            ///---向报表绑定数据源
            this.reportViewer1.LocalReport.DataSources.Add(rds2);


            ///---添加数据源
            ReportDataSource rds3 = new ReportDataSource();
            rds3.Name = "DataSet3";
            rds3.Value = table3;
            ///---向报表绑定数据源
            this.reportViewer1.LocalReport.DataSources.Add(rds3);


            ///---添加数据源
            ReportDataSource rds4 = new ReportDataSource();
            rds4.Name = "DataSet4";
            rds4.Value = table4;
            ///---向报表绑定数据源
            this.reportViewer1.LocalReport.DataSources.Add(rds4);

            ///---向报表查看器指定显示的报表
            this.reportViewer1.LocalReport.ReportPath = Application.StartupPath+"\\OQCreport1.rdlc";
            //this.reportViewer1.LocalReport.ReportPath =@"..\..\QM\OQCreport1.rdlc";
            ReportParameter rp1 = new ReportParameter("DH", QMFOQC.DH);
            reportViewer1.LocalReport.SetParameters(rp1);

            ReportParameter rp2 = new ReportParameter("SCZB", QMFOQC.SCZB);
            reportViewer1.LocalReport.SetParameters(rp2);

            ReportParameter rp3 = new ReportParameter("CPMC", QMFOQC.CPMC);
            reportViewer1.LocalReport.SetParameters(rp3);

            ReportParameter rp4 = new ReportParameter("KHBH", QMFOQC.KHBH);
            reportViewer1.LocalReport.SetParameters(rp4);

            ReportParameter rp5 = new ReportParameter("DDH", QMFOQC.DDH);
            reportViewer1.LocalReport.SetParameters(rp5);

            ReportParameter rp6 = new ReportParameter("DDPL", QMFOQC.DDPL.ToString());
            reportViewer1.LocalReport.SetParameters(rp6);

            ReportParameter rp7 = new ReportParameter("BPSL", QMFOQC.BPSL.ToString());
            reportViewer1.LocalReport.SetParameters(rp7);

            ReportParameter rp8 = new ReportParameter("ZCZ", QMFOQC.JYRY.ToString());
            reportViewer1.LocalReport.SetParameters(rp8);

            this.reportViewer1.RefreshReport();
        }
    }
}
